Skip to content

Conversation

@jennsun
Copy link
Contributor

@jennsun jennsun commented Jan 16, 2026

Added long term memory/retrieval features to our agent langgraph as a stateful agent example

Note: frontend e2e-chatbot-app interface does not support passing in custom input/thread id, only invocation calls on the endpoint. Have filed a ticket to support passing in chatcontext via frontend interface so we can use user id for namespacing

example app: https://eng-ml-agent-platform.staging.cloud.databricks.com/apps/j-longtermagent?o=2850744067564480

Example local testing:

curl -X POST http://localhost:8000/invocations \
  -H "Content-Type: application/json" \
  -d '{
    "input": [{"role": "user", "content": "Remember that my favorite color is blue"}],
    "context": {"user_id": "[email protected]"}
  }'

output from above:

{"object":"response","output":[{"type":"function_call","id":"lc_run--019b059a-09ec-79c3-bcf2-640edb80d37a","call_id":"toolu_bdrk_013tUwgLNctjrTSSSUBWShXQ","name":"save_user_memory","arguments":"{\"memory_key\": \"favorite_color\", \"memory_data_json\": \"{\\\"favorite_color\\\": \\\"blue\\\"}\"}"},{"type":"function_call_output","call_id":"toolu_bdrk_013tUwgLNctjrTSSSUBWShXQ","output":"Successfully saved memory with key 'favorite_color' for user."},{"type":"message","id":"lc_run--019b059a-20c5-76a1-be57-308598158d43","content":[{"text":"Got it! I've remembered that your favorite color is blue. 💙","type":"output_text","annotations":[]}],"role":"assistant"}]}

Follow-up:

curl -X POST http://localhost:8000/invocations \
  -H "Content-Type: application/json" \
  -d '{
    "input": [{"role": "user", "content": "What is my favorite color?"}],
    "context": {"user_id": "[email protected]"}
  }'

Output:

{"object":"response","output":[{"type":"function_call","id":"lc_run--019b059e-a723-76f3-98cb-46737a1ae5f4","call_id":"toolu_bdrk_01QXVHEFgp3VedAuc63HW1b6","name":"get_user_memory","arguments":"{\"query\": \"favorite color\"}"},{"type":"function_call_output","call_id":"toolu_bdrk_01QXVHEFgp3VedAuc63HW1b6","output":"User memories:\n- {\"favorite_color\": \"blue\"}"},{"type":"message","id":"lc_run--019b059e-cbd9-7252-86ff-2ae05615c341","content":[{"text":"Your favorite color is blue!","type":"output_text","annotations":[]}],"role":"assistant"}]}

seeing store tables are ready in app logs:
image

ensure user preferences are stored in lakebase:
image

Currently, cannot use long-term memory via frontend because user id is not passed in to context. Also made sure you cannot access another user's memories via frontend

image

App postman request:
image

Copy link
Contributor

@bbqiu bbqiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR looks awesome! left a few small nits, thank you for working on this!

# Check if LAKEBASE_INSTANCE_NAME already exists in app.yaml
if grep -q "name: LAKEBASE_INSTANCE_NAME" app.yaml; then
echo "LAKEBASE_INSTANCE_NAME already exists in app.yaml, skipping Lakebase setup..."
# Extract the existing value from app.yaml for display in summary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this? since app.yaml has valueFrom database instead of a real string value

can also make this an input param to match what sid also is working on making the quickstart command require less user input (so AI can run it fully): https://github.com/databricks/app-templates/pull/82/files#diff-0634e5169824dfbd324f2962bb69f68e1dd4445e4ee953cbe74b04e1ca9b8329

fi
echo "✓ Lakebase instance name saved to .env.local"

echo "Adding LAKEBASE_INSTANCE_NAME to app.yaml..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to replace the app.yaml value here?

echo "✓ Configuration files created (.env.local)"
echo "✓ MLflow experiment created: $EXPERIMENT_NAME"
echo "✓ Experiment ID: $EXPERIMENT_ID"
echo "✓ Configuration updated in .env.local"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we add a line here for the lakebase instance name

1. **Set up authentication to Databricks resources**
For this example, you need to add an MLflow Experiment and Lakebase instance as a resource to your app. Grant the App's Service Principal (SP) permission to edit the experiment by clicking `edit` on your app home page. See the [Databricks Apps MLflow experiment documentation](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/mlflow) for more information.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we add link to database docs

```
3. **Grant Lakebase permissions to your App's Service Principal**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we explain what's going on here? where connect + create doesn't grant perms for previously created schemas etc.

############################################
# Memory tools
############################################
def memory_tools():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we name it init_memory_tools to make it clear that this is to create them

@bbqiu bbqiu merged commit 3e28abf into databricks:main Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants